package com.ruoyi.machine.advanced.maintain.register.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.machine.advanced.maintain.register.domain.MaintainRegister;
import com.ruoyi.machine.advanced.maintain.register.service.IMaintainRegisterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备保养登记表
 * 控制层
 */
@RestController
@RequestMapping("/machine/maintain/register")
@Api(value = "设备保养登记模块", tags = "设备保养登记接口")
public class MaintainRegisterController extends BaseController {

    @Autowired
    private IMaintainRegisterService maintainRegisterService;

    /**
     * 获取设备保养登记表列表
     * @param maintainRegister
     * @return
     */
    @ApiOperationSupport(includeParameters = {"MaintainRegister.machineId", "MaintainRegister.maintainRegisterId"})
    @ApiOperation(value = "获取设备保养登记表列表",notes = "查询所有设备保养登记表信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody MaintainRegister maintainRegister) {

        startPage();

        List<MaintainRegister> maintainRegisterList = maintainRegisterService.selectMaintainRegisterList(maintainRegister);

        return getDataTable(maintainRegisterList);
    }

    /**
     * 导出设备保养登记表
     * @param maintainRegister
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody MaintainRegister maintainRegister) {

        List<MaintainRegister> maintainRegisterList = maintainRegisterService.selectMaintainRegisterList(maintainRegister);

        ExcelUtil<MaintainRegister> util = new ExcelUtil<>(MaintainRegister.class);

        return util.exportExcel(maintainRegisterList, "设备保养登记表数据");
    }

    /**
     * 新增设备保养登记表
     * @param maintainRegister
     * @return
     */
    @ApiOperation(value = "新增设备保养登记表", notes = "新增设备保养登记表")
    @ApiImplicitParam(name = "maintainRegister", value = "新增设备保养登记表", dataType = "MaintainRegister")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody MaintainRegister maintainRegister) {
        return toAjax(maintainRegisterService.insertMaintainRegister(maintainRegister));
    }

    /**
     * 修改设备保养登记表
     * @param maintainRegister
     * @return
     */
    @ApiOperation(value = "修改设备保养登记表", notes = "修改设备保养登记表")
    @ApiImplicitParam(name = "maintainRegister", value = "修改设备保养登记表", dataType = "MaintainRegister")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody MaintainRegister maintainRegister) {
        return toAjax(maintainRegisterService.updateMaintainRegister(maintainRegister));
    }

    /**
     * 删除设备保养登记表
     * 仅修改删除标志位
     * @param maintainRegister
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody MaintainRegister maintainRegister) {
        return toAjax(maintainRegisterService.updateMaintainRegisterDeleteFlag(maintainRegister));
    }

    /**
     * 查看天保养计划
     * @param maintainRegister
     * @return
     */
    @ApiOperation("查看天保养计划")
    @PostMapping("/day")
    public TableDataInfo day(@RequestBody MaintainRegister maintainRegister) {
        startPage();
        List<MaintainRegister> maintainRegisterList = maintainRegisterService.selectMaintainRegisterListDay(maintainRegister);
        return getDataTable(maintainRegisterList);
    }

    /**
     * 查看周保养计划
     * @param maintainRegister
     * @return
     */
    @ApiOperation("查看周保养计划")
    @PostMapping("/week")
    public TableDataInfo week(@RequestBody MaintainRegister maintainRegister) {
        startPage();
        List<MaintainRegister> maintainRegisterList = maintainRegisterService.selectMaintainRegisterListWeek(maintainRegister);
        return getDataTable(maintainRegisterList);
    }

    /**
     * 查看月保养计划
     * @param maintainRegister
     * @return
     */
    @ApiOperation("查看月保养计划")
    @PostMapping("/month")
    public TableDataInfo month(@RequestBody MaintainRegister maintainRegister) {
        startPage();
        List<MaintainRegister> maintainRegisterList = maintainRegisterService.selectMaintainRegisterListMonth(maintainRegister);
        return getDataTable(maintainRegisterList);
    }

    /**
     * 查看年保养计划
     * @param maintainRegister
     * @return
     */
    @ApiOperation("查看年保养计划")
    @PostMapping("/year")
    public TableDataInfo year(@RequestBody MaintainRegister maintainRegister) {
        startPage();
        List<MaintainRegister> maintainRegisterList = maintainRegisterService.selectMaintainRegisterListYear(maintainRegister);
        return getDataTable(maintainRegisterList);
    }
}
